/*     */ package change.org.eclipse.swt.browser;
/*     */ 
/*     */ import org.eclipse.swt.SWT;
/*     */ import org.eclipse.swt.layout.GridData;
/*     */ import org.eclipse.swt.layout.GridLayout;
/*     */ import org.eclipse.swt.widgets.Button;
/*     */ import org.eclipse.swt.widgets.Display;
/*     */ import org.eclipse.swt.widgets.Event;
/*     */ import org.eclipse.swt.widgets.Label;
/*     */ import org.eclipse.swt.widgets.Listener;
/*     */ import org.eclipse.swt.widgets.Shell;
/*     */ import org.mozilla.interfaces.nsICancelable;
/*     */ import org.mozilla.interfaces.nsIDOMWindow;
/*     */ import org.mozilla.interfaces.nsIDownload;
/*     */ import org.mozilla.interfaces.nsIFile;
/*     */ import org.mozilla.interfaces.nsIFileURL;
/*     */ import org.mozilla.interfaces.nsIHelperAppLauncher;
/*     */ import org.mozilla.interfaces.nsILocalFile;
/*     */ import org.mozilla.interfaces.nsIMIMEInfo;
/*     */ import org.mozilla.interfaces.nsIObserver;
/*     */ import org.mozilla.interfaces.nsIRequest;
/*     */ import org.mozilla.interfaces.nsISupports;
/*     */ import org.mozilla.interfaces.nsIURI;
/*     */ import org.mozilla.interfaces.nsIWebProgress;
/*     */ import org.mozilla.interfaces.nsIWebProgressListener;
/*     */ import org.mozilla.xpcom.Mozilla;
/*     */ 
/*     */ class MozillaDownload
/*     */   implements nsIDownload, nsIWebProgressListener
/*     */ {
/*     */   nsIHelperAppLauncher helperAppLauncher;
/*     */   Shell shell;
/*     */   Label status;
/*     */   Button cancel;
/*  30 */   static String DOWNLOAD = SWT.getMessage("SWT_Download") + " ";
/*  31 */   static String SAVING = SWT.getMessage("SWT_Saving") + " ";
/*  32 */   static String FROM = " " + SWT.getMessage("SWT_from") + " ";
/*  33 */   static String KO = SWT.getMessage("SWT_KB");
/*  34 */   static String OF = " " + SWT.getMessage("SWT_of") + " ";
/*     */ 
/*     */   public nsISupports queryInterface(String aIID)
/*     */   {
/*  40 */     return Mozilla.queryInterface(this, aIID);
/*     */   }
/*     */ 
/*     */   public void init(nsIURI aSource, nsIURI aTarget, String aDisplayName, nsIMIMEInfo aMIMEInfo, double startTime, nsILocalFile aTempFile, nsICancelable aCancelable)
/*     */   {
/*  47 */     String url = aSource.getHost();
/*     */ 
/*  50 */     String file_loc = "";
/*  51 */     nsIFileURL fileURL = (nsIFileURL)aTarget.queryInterface("{d26b2e2e-1dd1-11b2-88f3-8545a7ba7949}");
/*  52 */     if (fileURL != null) {
/*  53 */       nsIFile file = fileURL.getFile();
/*  54 */       if (file != null) {
/*  55 */         nsILocalFile localfile = (nsILocalFile)file.queryInterface("{aa610f20-a889-11d3-8c81-000064657374}");
/*     */ 
/*  58 */         file_loc = localfile.getLeafName();
/*     */       }
/*     */     }
/*     */ 
/*  62 */     Listener listener = new Listener() {
/*     */       public void handleEvent(Event event) {
/*  64 */         if (event.widget == MozillaDownload.this.cancel) {
/*  65 */           MozillaDownload.this.shell.close();
/*     */         }
/*  67 */         if (MozillaDownload.this.helperAppLauncher != null)
/*     */         {
/*  69 */           MozillaDownload.this.helperAppLauncher.cancel(-2142568446L);
/*     */         }
/*  71 */         MozillaDownload.this.shell = null;
/*  72 */         MozillaDownload.this.helperAppLauncher = null;
/*     */       }
/*     */     };
/*  76 */     this.shell = new Shell(2144);
/*  77 */     this.shell.setText(DOWNLOAD + file_loc);
/*  78 */     GridLayout gridLayout = new GridLayout();
/*  79 */     gridLayout.marginHeight = 15;
/*  80 */     gridLayout.marginWidth = 15;
/*  81 */     gridLayout.verticalSpacing = 20;
/*  82 */     this.shell.setLayout(gridLayout);
/*  83 */     new Label(this.shell, 64).setText(SAVING + file_loc + FROM + url);
/*  84 */     this.status = new Label(this.shell, 64);
/*  85 */     this.status.setText(DOWNLOAD);
/*  86 */     GridData data = new GridData();
/*  87 */     data.grabExcessHorizontalSpace = true;
/*  88 */     data.grabExcessVerticalSpace = true;
/*  89 */     this.status.setLayoutData(data);
/*     */ 
/*  91 */     this.cancel = new Button(this.shell, 8);
/*  92 */     this.cancel.setText(SWT.getMessage("SWT_Cancel"));
/*  93 */     data = new GridData();
/*  94 */     data.horizontalAlignment = 2;
/*  95 */     this.cancel.setLayoutData(data);
/*  96 */     this.cancel.addListener(13, listener);
/*  97 */     this.shell.addListener(21, listener);
/*  98 */     this.shell.pack();
/*  99 */     this.shell.open();
/*     */   }
/*     */ 
/*     */   public nsIObserver getObserver() {
/* 103 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public void setObserver(nsIObserver aObserver) {
/* 107 */     if (aObserver != null)
/* 108 */       this.helperAppLauncher = ((nsIHelperAppLauncher)aObserver.queryInterface("{99a0882d-2ff9-4659-9952-9ac531ba5592}"));
/*     */   }
/*     */ 
/*     */   public void onProgressChange64(nsIWebProgress arg1, nsIRequest arg2, long arg3, long arg4, long arg5, long arg6)
/*     */   {
/* 114 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public nsILocalFile getTargetFile()
/*     */   {
/* 120 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public int getPercentComplete() {
/* 124 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public double getAmountTransferred()
/*     */   {
/* 139 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public double getSize()
/*     */   {
/* 144 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public nsIURI getSource() {
/* 148 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public nsIURI getTarget() {
/* 152 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public nsICancelable getCancelable() {
/* 156 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public String getDisplayName() {
/* 160 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public long getStartTime() {
/* 164 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public nsIMIMEInfo getMIMEInfo() {
/* 168 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public void open(nsIDOMWindow aParent)
/*     */   {
/* 174 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public boolean getCancelDownloadOnClose() {
/* 178 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public void setCancelDownloadOnClose(boolean aCancelDownloadOnClose) {
/* 182 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public nsIDOMWindow getDialog() {
/* 186 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public void setDialog(nsIDOMWindow aDialog) {
/* 190 */     throw new RuntimeException("Not implemented.");
/*     */   }
/*     */ 
/*     */   public void onStateChange(nsIWebProgress aWebProgress, nsIRequest aRequest, long aStateFlags, long aStatus)
/*     */   {
/* 196 */     if ((aStateFlags & 0x10) != 0L) {
/* 197 */       this.helperAppLauncher = null;
/* 198 */       if ((this.shell != null) && (!(this.shell.isDisposed())))
/* 199 */         this.shell.dispose();
/* 200 */       this.shell = null;
/*     */     }
/*     */   }
/*     */ 
/*     */   public void onProgressChange(nsIWebProgress aWebProgress, nsIRequest aRequest, int aCurSelfProgress, int aMaxSelfProgress, int aCurTotalProgress, int aMaxTotalProgress)
/*     */   {
/* 206 */     int currentBytes = aCurTotalProgress / 1024;
/* 207 */     int totalBytes = aMaxTotalProgress / 1024;
/* 208 */     if ((((this.shell != null) ? 1 : 0) & ((this.shell.isDisposed()) ? 0 : 1)) != 0) {
/* 209 */       this.status.setText(DOWNLOAD + currentBytes + KO + OF + totalBytes + KO);
/* 210 */       this.shell.layout(true);
/* 211 */       this.shell.getDisplay().update();
/*     */     }
/*     */   }
/*     */ 
/*     */   public void onLocationChange(nsIWebProgress aWebProgress, nsIRequest aRequest, nsIURI aLocation)
/*     */   {
/*     */   }
/*     */ 
/*     */   public void onStatusChange(nsIWebProgress aWebProgress, nsIRequest aRequest, long aStatus, String aMessage)
/*     */   {
/*     */   }
/*     */ 
/*     */   public void onSecurityChange(nsIWebProgress aWebProgress, nsIRequest aRequest, long state)
/*     */   {
/*     */   }
/*     */ 
/*     */   public long getId()
/*     */   {
/* 230 */     return 0L;
/*     */   }
/*     */ 
/*     */   public nsIURI getReferrer()
/*     */   {
/* 235 */     return null;
/*     */   }
/*     */ 
/*     */   public boolean getResumable()
/*     */   {
/* 240 */     return false;
/*     */   }
/*     */ 
/*     */   public double getSpeed()
/*     */   {
/* 245 */     return 0.0D;
/*     */   }
/*     */ 
/*     */   public short getState()
/*     */   {
/* 250 */     return 0;
/*     */   }
/*     */ 
/*     */   public boolean onRefreshAttempted(nsIWebProgress arg0, nsIURI arg1, int arg2, boolean arg3)
/*     */   {
/* 255 */     return false;
/*     */   }
/*     */ }
